home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / xdme_1.84_src.lha / XDME / Src / Mod / gtb.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-22  |  39.5 KB  |  1,601 lines

  1. /*****************************************************************************
  2.     MODULE
  3.     GTB.c
  4.  
  5.     DESCRIPTION
  6.     XDME Command Module to support GADTOOLBOX projects as
  7.     additional parts of the GUI
  8.  
  9.     NOTES
  10.     GADTOOLS or GTX (at least one of them) seem to rely on the
  11.     order of creation so that menus must be created before gadgets,
  12.     else we get E-hits and a wrong font when opening the window
  13.  
  14.     BUGS
  15.     none known
  16.  
  17.     TODO
  18.     we still need an XDME interface ...
  19.  
  20.     EXAMPLES
  21.  
  22.     SEE ALSO
  23.  
  24.     AUTHOR
  25.     Bernd "0" Noll (b_noll@informatik.uni-kl.de)
  26.  
  27.     HISTORY
  28.     16-09-94 b_noll created
  29.     06-11-94 b_noll continued tests ... na endlich
  30.     09-11-94 b_noll cleanup
  31.     12-11-94 b_noll + ActivateGTBWindow
  32.     24-11-94 b_noll fixed setgbtgadget
  33.     27-11-94 b_noll first checks for non-gtbbased guis
  34.  
  35. ******************************************************************************/
  36.  
  37.  
  38. /**************************************
  39.           Includes
  40. **************************************/
  41.  
  42. //#include "defs.h"
  43.  
  44. #define PREFS_PREFHDR_H 1
  45.  
  46.  
  47. /* #include <intuition/intuitionbase.h> */
  48.  
  49.  
  50. #ifndef   GADTOOLSBOX_FORMS_H
  51. #include <gadtoolsbox/forms.h>
  52. #endif /* GADTOOLSBOX_FORMS_H */
  53.  
  54. #ifndef   CLIB_ALIB_PROTOS_H
  55. #include <clib/alib_protos.h>
  56. #endif /* CLIB_ALIB_PROTOS_H */
  57.  
  58. #include <proto/exec.h>
  59. #include <proto/utility.h>
  60. #include <proto/intuition.h>
  61. #include <proto/gadtools.h>
  62. #include <proto/nofrag.h>
  63. #include <proto/gtx.h>
  64.  
  65.  
  66.  
  67. #include <stdio.h>
  68.  
  69. #include "HL.h"
  70. #include "xdme_base.h"
  71.  
  72. #include "lists.h"
  73.  
  74.  
  75.  
  76. /* ---- Interface ... */
  77.  
  78. //#define GTB_FindProject(x) ((struct GTB_Project *)FindName((struct List *)GTB_Projects, (x)))
  79. //APTR GetHead (APTR);
  80. //APTR GetSucc (APTR);
  81. //#define DLL_Init(x)      NewList((struct List *)(x))
  82. //#define DLL_AddTail(x,y) AddTail((struct List *)(x),(y))
  83. //#define DLL_GetHead(x)   GetHead(x)
  84. //#define DLL_GetSucc(x,y) GetSucc(y)
  85. //extern  void DLL_Scan (struct MinList *l, void (*scan)(struct Node *, void *, int), void *ud);
  86. //#define DISPOSE(x) free(x) // free((x), sizeof(x))
  87. //#define NEW(x)     ((x) = malloc (sizeof (*(x))))
  88.  
  89. #define CloseWindowSafely closesharedwindow
  90. #define HL_FindName(l,x) HL_Find((l), (void *)NodeStringComparison, (x))
  91.  
  92.  
  93. /**************************************
  94.         Global Variables
  95. **************************************/
  96. struct GTXBase * GTXBase;
  97.  
  98.  
  99. /**************************************
  100.       Internal Defines & Structures
  101. **************************************/
  102.  
  103. //#define GTB_NOPROJECTACTIVE -16
  104. #define GTB_PROJECTACTIVE    -15
  105. #define GTB_WINDOWOPEN         -14
  106. #define GTB_WINDOWCLOSE      -13
  107. #define GTB_NOPORT         -12
  108. #define GTB_NOMEM         -11
  109. #define GTB_OK              0
  110.  
  111. #define GTB_BUFFERSIZE 1000
  112. #define GTB_DEFFMT    "%s-%s-%s '%s"
  113.           // Project-Window-Gadget 'Value
  114.  
  115. #define GTB_FixedDefWin 0
  116.  
  117. /**************************************
  118.        Internal Variables
  119. **************************************/
  120.  
  121. Prototype struct TextAttr GTB_Font;
  122. Prototype UBYTE      *GTB_Format;
  123. Prototype ULONG       GTB_SigMask;
  124.  
  125. #ifdef LOCAL_MEM
  126. #define       GTB_MemChain ((struct GTB_Project *)prj)->MemChain
  127. #else
  128. APTR          GTB_MemChain = NULL;
  129. #endif
  130. struct MsgPort     *GTB_Port     = NULL;
  131. ULONG          GTB_SigMask  = 0;
  132. struct TextAttr   GTB_Font     = { (STRPTR)"topaz.font", 8, 0x00, 0x01 };
  133. UBYTE         *GTB_Format   = NULL;
  134. UBYTE         *GTB_Buffer   = NULL;
  135. APTR          GTBRoot      = NULL;
  136. //struct DList       *GTB_Projects = NULL;
  137. static struct DList _GTB_Projects;
  138.  
  139. static struct Window *GTB_DefWindow = NULL;
  140.  
  141. /**************************************
  142.        Internal Prototypes
  143. **************************************/
  144.  
  145. //extern int  HL_Connect    (APTR base, APTR partner, ULONG attr);
  146. //extern void HL_Disconnect (APTR base, APTR partner);
  147. extern APTR HL_LockNode   (UBYTE *name);
  148.  
  149. /**************************************
  150.          Macros
  151. **************************************/
  152.  
  153.  
  154. /**************************************
  155.          Implementation
  156. **************************************/
  157.  
  158. struct GTB_Project {
  159.     struct HNode      Node;
  160.     struct HLASubs      AppliWindows;
  161.  
  162.  
  163.     APTR          VisualInfo;
  164.     struct WindowList      GuiWindows;
  165. #ifdef LOCAL_MEM
  166.     APTR          MemChain;
  167. #endif
  168.     WORD          OffsX, OffsY,
  169.               FactX, FactY,
  170.               DivX,  DivY,
  171.               FontX, FontY;
  172.     GUIDATA         *GuiData;
  173.     struct Screen     *IntuiScreen;
  174.     struct TextAttr      Font;
  175. }; /* struct GTB_Project */
  176.  
  177. struct WinNode {
  178.     struct HNode      Node;
  179.     struct HLASubs      AppliGadgets;
  180.  
  181.     //struct GTB_Project   *Parent;
  182.     struct Gadget     *IntuiGadgets;
  183.     struct Window     *IntuiWindow;
  184.     struct Menu      *IntuiMenus;
  185.     struct DList      AppliMenus;
  186.     struct ProjectWindow *GuiWindow;
  187. }; /* WinNode */
  188.  
  189.  
  190. /* not yet used */
  191. struct GadNode {
  192.     struct HNode      Node;
  193.     //struct WinNode       *Parent;
  194.  
  195.     struct Gadget     *IntuiGadget;
  196.     ULONG          LastCode;
  197.     APTR          gdata;
  198.     struct ExtNewGadget  *GuiGadget;
  199. }; /* GadNode */
  200.  
  201. /* not yet used */
  202. struct MenNode {
  203.     struct HNode      Node;
  204.     struct HLASubs      AppliSubs;
  205.  
  206.     struct ExtNewMenu     *GuiMenu;
  207.     struct MenuItem     *IntuiMenu;
  208.   //APTR          gdata;
  209. }; /* MenNode */
  210.  
  211.  
  212. #define Div(w,x)  (((struct GTB_Project *)w->Node.Parent)->Div  ## x)
  213. #define Fact(w,x) (((struct GTB_Project *)w->Node.Parent)->Fact ## x)
  214. #define Offs(w,x) (((struct GTB_Project *)w->Node.Parent)->Offs ## x)
  215.  
  216.  
  217. static int  GTB__ComputeWidX (struct WinNode *wn, int val) {
  218.     return ((val * 2 * Fact(wn,X) + Fact(wn,X)) / (2 * Div(wn,X)));
  219. } /* GTB__ComputeWidX */
  220.  
  221. static int  GTB__ComputeWidY (struct WinNode *wn, int val) {
  222.     return ((val * 2 * Fact(wn,Y) + Fact(wn,Y)) / (2 * Div(wn,Y)));
  223. } /* GTB__ComputeWidY */
  224.  
  225. static int  GTB__ComputePosX (struct WinNode *wn, int val) {
  226.     return ((val * 2 * Fact(wn,X) + Fact(wn,X)) / (2 * Div(wn,X)));
  227. } /* GTB__ComputePosX */
  228.  
  229. static int  GTB__ComputePosY (struct WinNode *wn, int val) {
  230.     return ((val * 2 * Fact(wn,Y) + Fact(wn,Y)) / (2 * Div(wn,Y))) + Offs(wn,Y);
  231.     //return val + wn->Parent->IntuiScreen->WBorTop + 1;
  232. } /* GTB__ComputePosY */
  233.  
  234.  
  235. /* ---------------------------------- */
  236. /* ---- close one window in a project */
  237. static int GTB_CloseWindow (struct WinNode *wn, struct GTB_Project *prj) {
  238. //puts ("GTB_Closewin");
  239.     if (wn->IntuiWindow) {
  240.     CloseWindowSafely(wn->IntuiWindow);
  241.     wn->IntuiWindow = NULL;
  242.     return GTB_OK;
  243.     } /* if */
  244.     return GTB_WINDOWCLOSE;
  245. } /* GTB_CloseWindow */
  246.  
  247.  
  248. static int GTB_RedrawWindow (struct WinNode *wn, struct GTB_Project *prj) {
  249.     struct ProjectWindow *pw;
  250.  
  251.     if (!wn->IntuiWindow)
  252.     return GTB_WINDOWCLOSE;
  253.  
  254.     pw = wn->GuiWindow;
  255.  
  256.     /* ---- Draw all ITexts */
  257.     {
  258.     struct IntuiText *it, itt;
  259.  
  260.     for (it = pw->pw_WindowText; it; it = it->NextText) {
  261.         //it->ITextFont   = &prj->Font;
  262.         itt         = *it;
  263.         itt.ITextFont   = &prj->Font;
  264.         itt.NextText    = NULL;
  265.         itt.LeftEdge    = GTB__ComputePosX( wn, itt.LeftEdge );
  266.         itt.TopEdge     = GTB__ComputePosY( wn, itt.TopEdge  );
  267.         PrintIText (wn->IntuiWindow->RPort, &itt, 0, 0);
  268.     } /* for */
  269.  
  270.     //PrintIText (wn->IntuiWindow->RPort, pw->pw_WindowText, 0, 0);
  271.     }
  272.  
  273.     /* ---- Draw all Boxes */
  274.     {
  275.     struct BevelBox *bv;
  276.  
  277.     for (bv = GetHead(&pw->pw_Boxes); bv; bv = GetSucc (bv)) {
  278.         DrawBevelBox ( wn->IntuiWindow->RPort,
  279.         GTB__ComputePosX( wn, bv->bb_Left   ),
  280.         GTB__ComputePosY( wn, bv->bb_Top    ),
  281.         GTB__ComputeWidX( wn, bv->bb_Width  ),
  282.         GTB__ComputeWidY( wn, bv->bb_Height ),
  283.         GTBB_Recessed, bv->bb_Flags & BBF_RECESSED,
  284.         //GTBB_FrameType, bv->bb_Flags & BBF_DROPBOX,
  285.         GT_VisualInfo, ((struct GTB_Project *)(wn->Node.Parent))->VisualInfo,
  286.         TAG_DONE );
  287.     } /* for */
  288.     }
  289. } /* GTB_RedrawWindow */
  290.  
  291.  
  292. /* --------------------------------- */
  293. /* ---- open one window in a project */
  294. static int GTB_OpenWindow (struct WinNode *wn, struct GTB_Project *prj) {
  295.     struct TagItem *tgs,
  296.            *tgh,
  297.            *tgw,
  298.            *tgi,
  299.            *tags,
  300.             tgadd[3] = { TAG_IGNORE, 0, TAG_IGNORE, 0, TAG_MORE };
  301.     struct Window  *win;
  302.  
  303. //puts ("GTB_Openwin");
  304.     if (wn->IntuiWindow)
  305.     return GTB_WINDOWOPEN;
  306.  
  307.     tags = wn->GuiWindow->pw_Tags;
  308.     tgadd[2].ti_Data = (ULONG)tags;
  309.  
  310.     /* ---- recalculate windimensions */
  311.  
  312.     if ((tgw = FindTagItem(WA_Width, tags))) {
  313.     tgadd[0].ti_Tag  = WA_Width;
  314.     tgadd[0].ti_Data = GTB__ComputePosX( wn, tgw->ti_Data );
  315.     //tgw->ti_Tag       = TAG_IGNORE;
  316.     } /* if */
  317.  
  318.     if ((tgh = FindTagItem(WA_Height, tags))) {
  319.     tgadd[1].ti_Tag  = WA_Height;
  320.     tgadd[1].ti_Data = GTB__ComputePosY( wn, tgh->ti_Data );
  321.     //tgh->ti_Tag       = TAG_IGNORE;
  322.     } /* if */
  323.  
  324.     /* ---- ignore customscreen & idcmp */
  325.     if ((tgs = FindTagItem (WA_CustomScreen, tags))) {
  326.     //tgs->ti_Tag = TAG_IGNORE;
  327.     tgs->ti_Data = (ULONG)prj->IntuiScreen;
  328.     } /* if customscreen */
  329.  
  330.     if ((tgi = FindTagItem (WA_IDCMP, tags))) {
  331.     tgi->ti_Tag = TAG_IGNORE;
  332.     } /* if needs idcmp */
  333.  
  334.     /* ---- Open the window */
  335.     win = OpenWindowTags(NULL,
  336.         WA_Gadgets, wn->IntuiGadgets,
  337.         TAG_MORE,    tgadd);
  338.  
  339.     /* ---- reinstall customscreen & idcmp */
  340.     if (tgi)
  341.     tgi->ti_Tag   = WA_IDCMP;
  342.  
  343.     //if (tgs)
  344.     //      tgs->ti_Tag    = WA_CustomScreen;
  345.     //if (tgw)
  346.     //      tgw->ti_Tag = WA_Width;
  347.     //if (tgh)
  348.     //      tgh->ti_Tag = WA_Height;
  349.  
  350.     /* ---- connect */
  351.     if (!(wn->IntuiWindow = win)) {
  352.     return GTB_WINDOWCLOSE;
  353.     } /* if */
  354.     win->UserData = (char *)wn;
  355.  
  356.     /* ---- if necessary set the right idcmp */
  357.     if (tgi && tgi->ti_Data) {
  358.     win->UserPort = GTB_Port;
  359.     ModifyIDCMP (win, tgi->ti_Data);
  360.     } /* if needs idcmp */
  361.  
  362.  
  363.     /* ---- install menu */
  364.     if (wn->IntuiMenus) {
  365.     SetMenuStrip(win, wn->IntuiMenus);
  366.     } /* if ex menu */
  367.  
  368.     GT_RefreshWindow( win, NULL );
  369.     GTB_RedrawWindow( wn, prj );
  370.  
  371.     return GTB_OK;
  372. } /* GTB_OpenWindow */
  373.  
  374.  
  375. /* ---- support function for _gtb_dropappliwindow */
  376. static void _gtb_dropappligadget (struct GadNode *gd, struct GTB_Project *prj) {
  377.  
  378.     // IntuiGadget Deletion is performed in _gtb_dropappliwindow
  379.  
  380. //puts ("GTB_Dropgad");
  381.     if (gd->gdata) {
  382.     HL_Disconnect (gd->gdata, &gd->Node);
  383.     }
  384.     HL_Uninit(&gd->Node);
  385.  
  386.     //Remove      (&gd->Node);
  387.     DISPOSE (gd);
  388. } /* _gtb_dropappligadget */
  389.  
  390.  
  391. /* ---- support function for _gtb_dropappliwindow */
  392. static void _gtb_dropapplimenu (struct MenNode *mn, struct GTB_Project *prj) {
  393.  
  394.     // IntuiMenu Deletion is performed in _gtb_dropappliwindow
  395. //puts ("GTB_Dropmenu");
  396.  
  397.     HL_Scan    (&mn->Node, (void *)_gtb_dropapplimenu, prj);
  398.     HL_Uninit    (&mn->Node);
  399.     DISPOSE    (mn);
  400. } /* _gtb_dropapplimenu */
  401.  
  402.  
  403. /* ---- support function for GTB_CloseProject */
  404. static void _gtb_dropappliwindow (struct WinNode *wn, struct GTB_Project *prj) {
  405.  
  406. //puts ("GTB_Dropwin");
  407.     GTB_CloseWindow (wn, prj);
  408.  
  409.     HL_Scan  (&wn->Node,         (void *)_gtb_dropappligadget, prj);
  410.     DLL_Scan (&wn->AppliMenus,   (void *)_gtb_dropapplimenu,   prj);
  411.  
  412.     if (wn->IntuiMenus) {
  413.     FreeMenus   (wn->IntuiMenus);
  414.     wn->IntuiMenus = NULL;
  415.     } /* if */
  416.     if (wn->IntuiGadgets) {
  417.     FreeGadgets (wn->IntuiGadgets);
  418.     wn->IntuiGadgets = NULL;
  419.     } /* if */
  420.  
  421.  
  422.     //Remove         (&wn->Node);
  423.     HL_Uninit       (&wn->Node);
  424.     DISPOSE       (wn);
  425. } /* _gtb_dropappliwindow */
  426.  
  427.  
  428. /* ---------------------- */
  429. /* ---- close one Project */
  430. static int GTB_CloseProject (struct GTB_Project *prj) {
  431.  
  432. //puts ("GTB_Dropprj");
  433.     /* ---- drop all windows */
  434.     HL_Scan (&prj->Node, (void *)_gtb_dropappliwindow, prj);
  435.  
  436.     if (prj->VisualInfo) {
  437.     FreeVisualInfo (prj->VisualInfo);
  438.     prj->VisualInfo = NULL;
  439.     } /* if */
  440.  
  441.     if (GTB_MemChain) {
  442.     GTX_FreeWindows (GTB_MemChain, &prj->GuiWindows);
  443.     FreeItem    (GTB_MemChain, prj->GuiData, sizeof (*prj->GuiData));
  444. #ifdef LOCAL_MEM
  445.     FreeMemoryChain (prj->MemChain, TRUE);
  446.     prj->MemChain = NULL;
  447. #endif
  448.     } /* if */
  449.  
  450.     HL_Uninit(&prj->Node);
  451.     //if (prj->Node.Name)
  452.     //      free (prj->Node.Name);
  453.     //Remove  (&prj->Node);
  454.     DISPOSE   (prj);
  455.     return GTB_OK;
  456. } /* GTB_CloseProject */
  457.  
  458.  
  459. static int ok;
  460. static int counter;
  461.  
  462. static void _gtb_countguimenus (struct ExtNewMenu *men) {
  463.     ++ counter;
  464.     if (((struct ExtNewMenu *)men)->em_Items)
  465.     DLL_Scan ((struct DList *)men->em_Items, (void *)_gtb_countguimenus, 0);
  466. } /* _gtb_countguimenus */
  467.  
  468. static void _gtb_copyguimenus (struct ExtNewMenu *men, void *x) {
  469.     ((struct NewMenu *)x)[counter] = men->em_NewMenu;
  470.     ((struct NewMenu *)x)[counter].nm_UserData = (APTR)men;
  471.     ++ counter;
  472.     if (men->em_Items)
  473.     DLL_Scan ((struct DList *)men->em_Items, (void *)_gtb_copyguimenus, x);
  474. } /* _gtb_copyguimenus */
  475.  
  476.  
  477. /* ---- part of GTB_OpenProject */
  478. static void _gtb_genappliwindow (struct ProjectWindow *pw, struct GTB_Project *prj) {
  479.     struct WinNode     *wn;
  480.     struct TagItem     *tg  = NULL;
  481.  
  482.     if (!ok)
  483.     return;
  484.  
  485.     /* ---- create the AppliWindow */
  486.     if (!NEW(wn)) {
  487.     ok = FALSE;
  488.     return;
  489.     } /* if */
  490.     bzero(wn, sizeof(*wn));
  491.     wn->GuiWindow    = pw;
  492.     //wn->IntuiMenus   = NULL;
  493.     //wn->IntuiGadgets = NULL;
  494.  
  495. #if 0
  496. {
  497. struct BevelBox *bv;
  498. struct IntuiText *it;
  499. printf ("WINDOW l=%s x=%d y=%d w=%d h=%d\n",
  500.     pw->pw_Name,
  501.     FindTagItem(WA_Left,   pw->pw_Tags)->ti_Data,
  502.     FindTagItem(WA_Top,    pw->pw_Tags)->ti_Data,
  503.     FindTagItem(WA_Width,  pw->pw_Tags)->ti_Data,
  504.     FindTagItem(WA_Height, pw->pw_Tags)->ti_Data,
  505.     0);
  506.  
  507. for (it = pw->pw_WindowText; it; it = it->NextText)
  508.     printf (" ITXT x=%d y=%d p=(%d %d) d=%d t='\n",
  509.     it->LeftEdge,
  510.     it->TopEdge,
  511.     it->FrontPen,
  512.     it->BackPen,
  513.     it->DrawMode,
  514.     it->IText,
  515.     /* TextAttr it->ITextFont */
  516.     0);
  517.  
  518. for (bv = GetHead(&pw->pw_Boxes); bv; bv = GetSucc (bv))
  519.     printf(" BBOX x=%d y=%d w=%d h=%d f=%d\n",
  520.     bv->bb_Left,
  521.     bv->bb_Top,
  522.     bv->bb_Width,
  523.     bv->bb_Height,
  524.     bv->bb_Flags,
  525.     0);
  526.  
  527. }
  528. #endif
  529.  
  530.     //wn->Parent       = prj;
  531.     //wn->Node.ln_Name = pw->pw_Name;
  532.     //DLL_Init     (&wn->AppliGadgets);
  533.     //DLL_AddTail(&prj->AppliWindows, &wn->Node);
  534.  
  535.     HL_Init(&wn->Node, pw->pw_Name, &prj->Node, HLF_SYSNODE|HLF_SUBCARRIER);
  536.  
  537.     DLL_Init   (&wn->AppliMenus);
  538.  
  539.  
  540.     /* ---- Create the Menu structures */
  541.     {
  542.     int            numnm;
  543.     struct NewMenu       *nmb;
  544.  
  545.     counter = 0;
  546.     DLL_Scan ((struct DList *)&pw->pw_Menus, (void *)_gtb_countguimenus, 0);
  547.  
  548.     if (counter) {
  549.         numnm = counter + 1;
  550.  
  551.         if (!(nmb = AllocMem (sizeof (struct NewMenu) * numnm, 0))) {
  552.         ok = FALSE;
  553.         return;
  554.         } /* if */
  555.  
  556.         counter = 0;
  557.         DLL_Scan ((struct DList *)&pw->pw_Menus, (void *)_gtb_copyguimenus, nmb);
  558.         nmb[counter].nm_Type = NM_END;
  559.  
  560.         wn->IntuiMenus = CreateMenus (nmb, TAG_DONE);
  561.         FreeMem (nmb, sizeof (struct NewMenu) * numnm);
  562.         if (!wn->IntuiMenus) {
  563.         ok = FALSE;
  564.         return;
  565.         } else {
  566.         LayoutMenusA (wn->IntuiMenus, prj->VisualInfo, TAG_END);
  567.         } /* if */
  568.     } /* if menues */
  569.     }
  570.  
  571. //if (!GETF_DEBUG(Ep))
  572.     /* ---- Create the Gadget structures */
  573.     {
  574.     struct ExtNewGadget *pg;
  575.     struct Gadget        *gad = NULL;
  576.     struct NewGadget     ng;
  577.  
  578.     if (!(gad = CreateContext(&wn->IntuiGadgets))) {
  579.         ok = 0;
  580.     } /* if */
  581.  
  582.     for (pg = GetHead(&pw->pw_Gadgets); ok && pg; pg = GetSucc(pg)) {
  583.         struct GadNode *gd;
  584. //printf ("gad: %s\n", pg->en_GadgetLabel);
  585.         if (!NEW(gd)) {
  586.         ok = FALSE;
  587.         return;
  588.         } /* if */
  589.         gd->GuiGadget    = pg;
  590.         gd->LastCode     = 0;
  591.         //gd->Node.ln_Name = pg->en_GadgetLabel;
  592.         //gd->Parent       = wn;
  593.         //DLL_AddTail (&wn->AppliGadgets, &gd->Node);
  594.         HL_Init(&gd->Node, pg->en_GadgetLabel, &wn->Node, HLF_SYSNODE);
  595.  
  596.         /* ---- Listviews w/ ShowSelected are preceeded by their partner */
  597.         if (pg->en_Kind == LISTVIEW_KIND) {
  598.         tg = FindTagItem (GTLV_ShowSelected, pg->en_Tags);
  599.         if (tg && tg->ti_Data) {
  600.             tg->ti_Data = (ULONG)gad;
  601.         } /* if needs company */
  602. #ifndef ONLY_V39
  603.         } else if (pg->en_Kind == CHECKBOX_KIND) {
  604.         tg = FindTagItem (GTCB_Checked, pg->en_Tags);
  605.         if (tg && tg->ti_Data) {
  606.             gd->LastCode = 1;
  607.         } /* if is selected checkbox */
  608. #endif
  609.         } /* if certain kind */
  610.  
  611.         /* ---- GenericKind is not (yet) supported */
  612.         if (pg->en_Kind == GENERIC_KIND) {
  613.         ok = 0;
  614.         break;
  615.         } /* if is genkind */
  616.  
  617.         ng    = pg->en_NewGadget;
  618.         ng.ng_VisualInfo = prj->VisualInfo;
  619.         ng.ng_TextAttr   = &prj->Font;
  620.         ng.ng_LeftEdge   = GTB__ComputePosX( wn, ng.ng_LeftEdge );
  621.         ng.ng_TopEdge    = GTB__ComputePosY( wn, ng.ng_TopEdge  );
  622.         ng.ng_Width      = GTB__ComputeWidX( wn, ng.ng_Width    );
  623.         ng.ng_Height     = GTB__ComputeWidY( wn, ng.ng_Height   );
  624.  
  625.         gad = CreateGadgetA (pg->en_Kind, gad, &ng, pg->en_Tags);
  626.         if (!gad) {
  627.         ok = 0;
  628.         break;
  629.         } /* if */
  630.         gad->UserData    = gd;
  631.         gd->IntuiGadget  = gad;
  632.         gd->gdata         = NULL;
  633. //if (GETF_ABORTCOMMAND(Ep)) break;
  634.     } /* for all gads */
  635.     }
  636. } /* _gtb_genappliwindow */
  637.  
  638.  
  639. /* Include this one so I do not need to give the gtx.lib along */
  640. LONG GTX_LoadGUI (struct MemoryChain * mch, UBYTE * filename, Tag tag,
  641.             ...)
  642. {
  643.     return GTX_LoadGUIA (mch, filename, (struct TagItem *)&tag);
  644. } /* GTX_LoadGUI */
  645.  
  646.  
  647. /* --------------------- */
  648. /* ---- open one project */
  649. int GTB_OpenProject (const char *filename, const char *label) {
  650.     ULONG        valid = 0;
  651.     int         error = 0;
  652.     struct GTB_Project *prj;
  653.  
  654.     /* ---- is the module correctly initialized ? */
  655.     if (!GTB_Port) {
  656.     return GTB_NOPORT;
  657.     } /* if */
  658.  
  659.     /* ---- is a duplicate elimination necessary? */
  660.     if (prj = (void *)HL_FindName (GTBRoot, label)) {
  661.     return GTB_PROJECTACTIVE;
  662.     } /* if */
  663.  
  664.     /* ---- init the project */
  665.     {
  666.     if (!NEW(prj)) {
  667.         return GTB_NOMEM;
  668.     } /* if */
  669.     bzero (prj, sizeof(*prj));
  670.  
  671.     /* ---- basics */
  672.     DLL_Init      ((struct DList *)&prj->GuiWindows);
  673.     //DLL_AddTail (GTB_Projects, &prj->Node); DLL_Init (&prj->AppliWindows);
  674.  
  675.     if (HL_Init(&prj->Node, label, GTBRoot, HLF_SYSNODE|HLF_SUBCARRIER) != HL_OK) {
  676.         GTB_CloseProject (prj);
  677.         return GTB_NOMEM;
  678.     } /* if */
  679.  
  680. #ifdef LOCAL_MEM
  681.     /* ---- local memory chain */
  682.     if (!(prj->MemChain = GetMemoryChain(4096))) {
  683.         GTB_CloseProject (prj);
  684.         return GTB_NOMEM;
  685.     } /* if */
  686. #endif
  687.  
  688.     /* ---- node/name */
  689.     if (!(prj->Node.Name = strdup (label))) {
  690.         GTB_CloseProject (prj);
  691.         return GTB_NOMEM;
  692.     } /* if */
  693.  
  694.     /* ---- heap for .gui information */
  695.     if (!(prj->GuiData = AllocItem(GTB_MemChain, sizeof (*prj->GuiData), MEMF_CLEAR))) {
  696.         GTB_CloseProject (prj);
  697.         return GTB_NOMEM;
  698.     } /* if */
  699.     }
  700.  
  701.     /* ---- Load the GuiWindows */
  702.     error = (int)GTX_LoadGUI(GTB_MemChain, filename,
  703.                 RG_WindowList, &prj->GuiWindows,
  704.                 RG_GUI,        prj->GuiData,
  705.                 RG_Valid,       &valid,
  706.                 TAG_DONE );
  707. //printf ("error %d valid %08lx (%08lx)\n", error, valid, VLF_WINDOWLIST|VLF_GUI);
  708.  
  709.     if (error) {
  710.     GTB_CloseProject(prj);
  711.     return -error;
  712.     } /* if */
  713.  
  714.     if (valid != (VLF_GUI|VLF_WINDOWLIST)) {
  715.     GTB_CloseProject(prj);
  716.     return -ERROR_NOTGUIFILE;
  717. //#define ERROR_NOMEM              1
  718. //#define ERROR_OPEN              2
  719. //#define ERROR_READ              3
  720. //#define ERROR_WRITE              4
  721. //#define ERROR_PARSE              5
  722. //#define ERROR_PACKER              6
  723. //#define ERROR_PPLIB              7
  724. //#define ERROR_NOTGUIFILE          8
  725.     } /* if */
  726.  
  727.     /* ---- Screen specifics */
  728.     {
  729.     struct Screen *screen;
  730. // naja ... solange wir noch nicht am xdme kleben ...
  731. //#define ___SCREEN___ IntuitionBase->ActiveScreen
  732. #define   ___SCREEN___ active_window()->WScreen
  733.     prj->IntuiScreen = ___SCREEN___;
  734.     screen = prj->IntuiScreen;
  735.  
  736.     if (!(prj->VisualInfo = GetVisualInfo(screen, TAG_DONE))) {
  737.         GTB_CloseProject (prj);
  738.         return GTB_NOMEM;
  739.     } /* if */
  740.  
  741.     //if ((prj->GuiData->gui_Font.ta_YSize == 8) && !stricmp(prj->GuiData->gui_Font.ta_Name, "topaz.font")) {
  742.     //    prj->Font.ta_Name  = (STRPTR)screen->RastPort.Font->tf_Message.mn_Node.ln_Name;
  743.     //    prj->Font.ta_YSize = prj->FontY = screen->RastPort.Font->tf_YSize;
  744. //printf ("projectfont: %s\\%d, used:%s\\%d, fontname:%s \n",
  745. //prj->GuiData->gui_Font.ta_Name, prj->GuiData->gui_Font.ta_YSize,
  746. //prj->Font.ta_Name, prj->Font.ta_YSize,
  747. //prj->GuiData->gui_FontName );
  748.     //               prj->FontX = screen->RastPort.Font->tf_XSize;
  749.     //} else
  750.     {
  751.         /* ---- use the font found referenced in the GUI */
  752.         prj->Font.ta_Name            = prj->GuiData->gui_Font.ta_Name;
  753.         prj->Font.ta_YSize = prj->FontY = prj->GuiData->gui_Font.ta_YSize;
  754.                  prj->FontX = prj->GuiData->gui_Font.ta_YSize;
  755.     } /* if */
  756.  
  757.     prj->DivX  = prj->GuiData->gui_Font.ta_YSize;
  758.     prj->DivY  = prj->GuiData->gui_Font.ta_YSize;
  759.     prj->OffsY = screen->RastPort.TxHeight + screen->WBorTop + 1 - prj->DivY;
  760.     prj->OffsX = screen->WBorLeft;
  761.     prj->FactX = prj->FontX;
  762.     prj->FactY = prj->FontY;
  763.     }
  764.  
  765.     /* ---- Create (Appli-Items and) partly Intui-Items for all Gui-Items */
  766.     ok = TRUE;
  767.     DLL_Scan ((struct DList *)&prj->GuiWindows, (void *)_gtb_genappliwindow, prj);
  768.  
  769.     if (!ok) {
  770.     GTB_CloseProject(prj);
  771.     return GTB_NOMEM;
  772.     } /* if */
  773.  
  774.     return GTB_OK;
  775. } /* GTB_OpenProject */
  776.  
  777.  
  778. /***************************************************
  779.           APPLICATION INTERFACE
  780. ***************************************************/
  781.  
  782.  
  783. // std way is gonna be sprintf (GTB_Buffer, GTB_Format, wnd->Label, gad->Label, gad->Value); do_command (GTB_Buffer);
  784. Prototype int GTB_Control (void);
  785. int GTB_Control (void) {
  786.     struct IntuiMessage     *m, msg;
  787.     struct ExtNewGadget     *en;
  788.     struct ExtNewMenu        *em;
  789.     struct MenuItem        *n;
  790.     struct Window        *wnd;
  791.     struct WinNode        *wn;
  792.     struct GadNode        *gd;
  793.     BOOL            running = TRUE;
  794.     char            valbuffer[16];
  795.     char            *value;
  796.  
  797.     while(( m = GT_GetIMsg( GTB_Port ))) {
  798.  
  799.     msg = *m;
  800.     wnd = msg.IDCMPWindow;
  801.     wn  = (struct WinNode *)wnd->UserData;
  802.  
  803.     GT_ReplyIMsg( m );
  804.  
  805.     switch ( msg.Class ) {
  806.  
  807.     case    IDCMP_REFRESHWINDOW:
  808.         GT_BeginRefresh ( wnd );
  809.         GTB_RedrawWindow( wn, (struct GTB_Project *)wn->Node.Parent);
  810.         GT_EndRefresh   ( wnd, TRUE );
  811.         break;
  812.  
  813.     case    IDCMP_CLOSEWINDOW:
  814.         GTB_CloseWindow (wn, (struct GTB_Project *)wn->Node.Parent);
  815.         running = 0;
  816.         break;
  817.  
  818.     case    IDCMP_GADGETUP:
  819.       //case    IDCMP_GADGETDOWN:
  820.         gd = ( void * )(( struct Gadget * )msg.IAddress )->UserData;
  821.         en = gd->GuiGadget;
  822. //printf ("Selected Gadget: %s\n", en->en_GadgetLabel);
  823.         switch (en->en_Kind) {
  824.         case CHECKBOX_KIND:
  825. #ifndef ONLY_V39
  826.         gd->LastCode = !gd->LastCode;
  827.         sprintf (valbuffer, "%d", gd->LastCode);
  828.         value = valbuffer;
  829.         break;
  830. #endif
  831.         case LISTVIEW_KIND:
  832.         case MX_KIND:
  833.         case CYCLE_KIND:
  834.         case PALETTE_KIND:
  835.         case SCROLLER_KIND:
  836.         case SLIDER_KIND:
  837.         sprintf (valbuffer, "%d", (int)msg.Code);
  838.         value = valbuffer;
  839. //printf (" value = %d\n", (int)msg.Code);
  840.         gd->LastCode = msg.Code;
  841.         break;
  842.         case INTEGER_KIND:
  843.         gd->LastCode = ((struct StringInfo *)((struct Gadget *)msg.IAddress)->SpecialInfo)->LongInt;
  844.         case STRING_KIND:
  845. //printf (" value = %s\n", ((struct StringInfo *)((struct Gadget *)msg.IAddress)->SpecialInfo)->Buffer);
  846.         value = ((struct StringInfo *)((struct Gadget *)msg.IAddress)->SpecialInfo)->Buffer;
  847.         break;
  848.         case BUTTON_KIND:
  849. //printf (" button\n");
  850.         value = "";
  851.         break;
  852.         case TEXT_KIND:
  853.         case NUMBER_KIND:
  854. //printf (" no value possible !?\n");
  855.         /* nop */
  856.         break;
  857.         } /* switch */
  858.  
  859. //printf ("build...\n");
  860.         sprintf (GTB_Buffer, GTB_Format,
  861.             wn->Node.Parent->Name,
  862.             wn->Node.Name,
  863.             en->en_GadgetLabel,
  864.             value,
  865.             wn->Node.Parent->Name,
  866.             wn->Node.Name,
  867.             en->en_GadgetLabel,
  868.             value,
  869.             wn->Node.Parent->Name,
  870.             wn->Node.Name,
  871.             en->en_GadgetLabel,
  872.             value );
  873. //printf ("%s\neval...\n", GTB_Buffer);
  874.         do_command (GTB_Buffer);
  875.  
  876.         break;
  877.  
  878.     case    IDCMP_MENUPICK:
  879.         while( msg.Code != MENUNULL ) {
  880.         n = ItemAddress( wnd->MenuStrip, msg.Code );
  881.         em = (void *)(GTMENUITEM_USERDATA( n ));
  882. //printf ("Selected Menu: %s\n", em->em_MenuLabel);
  883.         if (n->Flags & CHECKIT) {
  884. //printf (" value = %d\n", (n->Flags & CHECKED) ? 1 : 0);
  885.             sprintf (valbuffer, "%d", (n->Flags & CHECKED) ? 1 : 0);
  886.             value = valbuffer;
  887.         } else {
  888.             value = "";
  889. //printf (" no value\n");
  890.         } /* if */
  891.  
  892.         sprintf (GTB_Buffer, GTB_Format,
  893.             wn->Node.Parent->Name,
  894.             wn->Node.Name,
  895.             em->em_MenuLabel,
  896.             value,
  897.             wn->Node.Parent->Name,
  898.             wn->Node.Name,
  899.             em->em_MenuLabel,
  900.             value,
  901.             wn->Node.Parent->Name,
  902.             wn->Node.Name,
  903.             em->em_MenuLabel,
  904.             value );
  905.         do_command (GTB_Buffer);
  906.  
  907.         msg.Code = n->NextSelect;
  908.         } /* while */
  909.         break;
  910.     } /* switch */
  911.     } /* while */
  912.  
  913.     return running;
  914. } /* GTB_Control */
  915.  
  916.  
  917.  
  918. int libopen(void) {
  919.     /* SysBase = *(struct Library **)4l; */
  920.  
  921.     GTXBase = (struct GTXBase *)OpenLibrary ("gadtoolsbox.library", 37);
  922.     if (!GTXBase)
  923.     return -1;
  924.  
  925.     NoFragBase = (struct NoFragBase *)OpenLibrary ("nofrag.library", 2);
  926.     if (!NoFragBase)
  927.     return -2;
  928.  
  929.     return 0;
  930. }
  931.  
  932. static void libclose(void) {
  933.     if (GTXBase)
  934.     CloseLibrary((struct Library *)GTXBase);
  935.     GTXBase = NULL;
  936.  
  937.     if (NoFragBase)
  938.     CloseLibrary((struct Library *)NoFragBase);
  939.     NoFragBase = NULL;
  940.  
  941. }
  942.  
  943.  
  944. /* ---- close the whole GTB module */
  945. DEFAUTOEXIT( GTB_Terminate )
  946. {
  947.  
  948.     /* ---- close all Projects */
  949.     HL_Scan   (GTBRoot, (void *)GTB_CloseProject, NULL);
  950.     HL_Dispose(GTBRoot);
  951.  
  952. #ifndef LOCAL_MEM
  953.     if (GTB_MemChain)
  954.     FreeMemoryChain (GTB_MemChain, TRUE);
  955.     GTB_MemChain = NULL;
  956. #endif
  957.  
  958.     if (GTB_Port)
  959.     DeleteMsgPort (GTB_Port);
  960.     GTB_Port = NULL;
  961.  
  962.     if (GTB_Format)
  963.     free (GTB_Format);
  964.     GTB_Format = NULL;
  965.  
  966.     if (GTB_Buffer)
  967.     free(GTB_Buffer);
  968.     GTB_Buffer = NULL;
  969.  
  970.     if (GTB_DefWindow)
  971.     CloseWindow(GTB_DefWindow);
  972.     GTB_DefWindow = NULL;
  973.  
  974.     /* if (GTB_)
  975.     (GTB_);
  976.     GTB_ = NULL; */
  977.  
  978.     GTB_SigMask = 0;
  979.     libclose();
  980. } /* GTB_Terminate */
  981.  
  982.  
  983. /* ---- init the GTB module */
  984. DEFAUTOINIT( GTB_Initialize )
  985. {
  986. //puts (__FILE__);
  987.  
  988.     //GTB_Projects = &_GTB_Projects; DLL_Init (GTB_Projects);
  989.  
  990.     GTBRoot     = HL_SystemList("*GtbProjects*");
  991.     if (!GTBRoot)
  992.     return;
  993.     //GTB_Projects = HL_InstSubs(GTBRoot);
  994.  
  995.     if (libopen() != 0)
  996.     return;
  997.  
  998.     /* ---- failing ops */
  999.     GTB_Port     = CreateMsgPort();
  1000.     GTB_Format     = strdup(GTB_DEFFMT);
  1001.     GTB_Buffer     = malloc(GTB_BUFFERSIZE);
  1002. #ifndef LOCAL_MEM
  1003.     GTB_MemChain = GetMemoryChain(4096);
  1004. #endif
  1005.  
  1006.     /* ---- validity checks */
  1007.  
  1008. #ifndef LOCAL_MEM
  1009.     if ( !GTB_Port || !GTB_MemChain || !GTB_Format || !GTB_Buffer )
  1010. #else
  1011.     if ( !GTB_Port ||                  !GTB_Format || !GTB_Buffer )
  1012. #endif
  1013.     {
  1014.     GTB_Terminate ();
  1015.     return;
  1016.     } /* if */
  1017.  
  1018.     /* ---- non-failing ops */
  1019.     GTB_SigMask = 1 << GTB_Port->mp_SigBit;
  1020.  
  1021. } /* GTB_Initialize */
  1022.  
  1023.  
  1024.  
  1025. int GTB_Error (int code) {
  1026.     //char **av; av = (char **)(&code+1);
  1027.  
  1028.     switch (code) {
  1029.     case GTB_OK:
  1030.     return RET_SUCC;
  1031.     case GTB_NOMEM:
  1032.     nomemory();
  1033.     break;
  1034.     case GTB_PROJECTACTIVE:
  1035.     error("%s:\nProject '%s' is already used!", av[0], av[1]);
  1036.     break;
  1037.     case GTB_WINDOWOPEN:
  1038.     error("%s:\nWindow '%s' is open!", av[0], av[2]);
  1039.     break;
  1040.     case GTB_WINDOWCLOSE:
  1041.     error("%s:\nWindow '%s' is closed!", av[0], av[2]);
  1042.     break;
  1043.     case GTB_NOPORT:
  1044.     error("%s:\nGadToolsBox module not active", av[0]);
  1045.     break;
  1046.     default:
  1047.     error("%s:\nunknown error code %ld", av[0], (long)code);
  1048.     } /* switch */
  1049.     return RET_FAIL;
  1050. } /* GTB_Error */
  1051.  
  1052.  
  1053.  
  1054. /*************************************************
  1055.     Fragments of other modules
  1056. *************************************************/
  1057.  
  1058. #ifdef MAIN_C
  1059.  
  1060. DEFSIGHANDLER( GTB_SigMask, GTB_Control(); )
  1061.  
  1062. #endif
  1063.  
  1064. /***************************************************
  1065.         COMMAND INTERFACE
  1066. ***************************************************/
  1067.  
  1068. /*DEFHELP #cmd special GTB - The GadToolsBox Interface */
  1069.  
  1070. static void GTB_SetGadgetAttrsA (struct GadNode *gd, struct TagItem *tg)
  1071. {
  1072.     struct GTB_Project *prj;
  1073.     struct WinNode     *wn;
  1074.     if (gd) {
  1075.     wn  = (void *)gd->Node.Parent;
  1076.  
  1077.     if (!wn) {
  1078.         return;
  1079.     } /* if */
  1080.  
  1081. #ifndef ONLY_V39
  1082.         /* ---- V37 Fix ... the machine freezes, if we call     */
  1083.         /*        GT_SetGadgetAttrs with NULL windowptr in OS 2.x */
  1084.         if ((GadToolsBase->/*LibNode.*/lib_Version == 37) && !(wn->IntuiWindow)) {
  1085.         prj = (void *)wn->Node.Parent;
  1086.         if (!AmTerminating) {
  1087.             if (!(GTB_DefWindow) && !(GTB_DefWindow = OpenWindowTags(NULL,
  1088.                 WA_Height,     1,
  1089.                 WA_Width,     1,
  1090.                 WA_Left,     0,
  1091.                 WA_Top,    20,
  1092.                 WA_IDCMP,     0,
  1093.                 WA_Backdrop, 1,
  1094.                 WA_Gadgets,      wn->IntuiGadgets,
  1095.                 WA_CustomScreen, prj->IntuiScreen,
  1096.                 TAG_END))) {
  1097.             error ("%s:\nCannot open fallback window!", av[0]);
  1098.             } else {
  1099.             GT_SetGadgetAttrsA (gd->IntuiGadget,
  1100.                     GTB_DefWindow, NULL, tg);
  1101.             /* ---- since the defwindow contains our wingads, we must */
  1102.             /*    close it again to avoid confusion          */
  1103.             if (!GTB_FixedDefWin) {
  1104.                 CloseWindow (GTB_DefWindow);
  1105.                 GTB_DefWindow = NULL;
  1106.             } /* if */
  1107.             } /* if */
  1108.         } /* if */
  1109.         } else
  1110. #endif
  1111.         GT_SetGadgetAttrsA (gd->IntuiGadget,
  1112.                 wn->IntuiWindow, NULL, tg);
  1113.     } /* if */
  1114. } /* GTB_SetGadgetAttrsA */
  1115.  
  1116.  
  1117. static struct GTB_Project *_getgtbproject (void) {
  1118.     struct GTB_Project *prj;
  1119.     if ((prj = (void *)HL_FindName (GTBRoot, av[1])))
  1120.     return prj;
  1121.     error ("%s:\nProject %s does not (yet) exist", av[0], av[1]);
  1122.     return NULL;
  1123. } /* do_getgtbproject */
  1124.  
  1125. static struct WinNode *_getgtbwindow (void) {
  1126.     struct GTB_Project *prj;
  1127.     if (prj = _getgtbproject()) {
  1128.     struct WinNode *wn;
  1129.     if ((wn = (void *)HL_FindName (&prj->Node, av[2])))
  1130.         return wn;
  1131.     error ("%s:\n No window of name '%s'\n in project '%s'", av[0], av[2], av[1]);
  1132.     } /* if */
  1133.     return NULL;
  1134. } /* _getgtbwindow */
  1135.  
  1136. static struct GadNode * _getgtbgadget (void) {
  1137.     struct WinNode *wn;
  1138.     if ((wn = _getgtbwindow())) {
  1139.     struct GadNode *gd;
  1140.     if ((gd = (void *)HL_FindName (&wn->Node, av[3])))
  1141.         return gd;
  1142.     error ("%s:\n No gadget of name '%s'\n in window '%s' of project '%s'", av[0], av[3], av[2], av[1]);
  1143.     } /* if */
  1144.     return NULL;
  1145. } /* _getgtbgadget */
  1146.  
  1147. /*DEFHELP #cmd gtb SETGTBGADGET project window gadget value - set another value to a GTB gadget */
  1148. DEFUSERCMD("SetGTBGadget", 4, CF_VWM|CF_ICO|CF_COK, void, do_setgtbgadget, (void), )
  1149. {
  1150.     struct TagItem tg[2] = {TAG_IGNORE, 0, TAG_END };
  1151.     struct WinNode     *wn;
  1152.     struct GTB_Project *prj;
  1153.     struct GadNode     *gd;
  1154.  
  1155.     if (gd  = _getgtbgadget()) {
  1156.     wn  = (void *)gd->Node.Parent;
  1157.     prj = (void *)wn->Node.Parent;
  1158.  
  1159.     switch (gd->GuiGadget->en_Kind) {
  1160.     case CHECKBOX_KIND:
  1161.     case LISTVIEW_KIND:
  1162.     case MX_KIND:
  1163.     case CYCLE_KIND:
  1164.     case PALETTE_KIND:
  1165.     case SCROLLER_KIND:
  1166.     case SLIDER_KIND:
  1167.     case NUMBER_KIND:
  1168.     case INTEGER_KIND:
  1169.         tg[0].ti_Data = atol (av[4]);
  1170.         break;
  1171.  
  1172.     case STRING_KIND:
  1173.         tg[0].ti_Data = (ULONG)(av[4]);
  1174.         break;
  1175.  
  1176.     case TEXT_KIND: /* hmmm not sufficient ... how about abusing the */
  1177.             /* lastcode field ? */
  1178.         tg[0].ti_Data = (ULONG)(av[4]);
  1179.         error ("%s:\nText gadgets can not yet be set!", av[0]);
  1180.         return;
  1181.         break;
  1182.  
  1183.     case BUTTON_KIND:
  1184.         error ("%s:\n Buttons can't get values!\n", av[0]);
  1185.         return;
  1186.     default:
  1187.         error ("%s:\nUnknown gadget type!", av[0]);
  1188.         return;
  1189.     } /* switch */
  1190.  
  1191.     switch (gd->GuiGadget->en_Kind) {
  1192.     case CHECKBOX_KIND:
  1193.         tg[0].ti_Tag = GTCB_Checked;
  1194.         break;
  1195.     case LISTVIEW_KIND:
  1196.         tg[0].ti_Tag = GTLV_Selected;
  1197.         break;
  1198.     case MX_KIND:
  1199.         tg[0].ti_Tag = GTMX_Active;
  1200.         break;
  1201.     case CYCLE_KIND:
  1202.         tg[0].ti_Tag = GTCY_Active;
  1203.         break;
  1204.     case PALETTE_KIND:
  1205.         tg[0].ti_Tag = GTPA_Color;
  1206.         break;
  1207.     case SCROLLER_KIND:
  1208.         tg[0].ti_Tag = GTSC_Top;
  1209.         break;
  1210.     case SLIDER_KIND:
  1211.         tg[0].ti_Tag = GTSL_Level;
  1212.         break;
  1213.     case NUMBER_KIND:
  1214.         tg[0].ti_Tag = GTNM_Number;
  1215.         break;
  1216.     case INTEGER_KIND:
  1217.         tg[0].ti_Tag = GTIN_Number;
  1218.         break;
  1219.     case STRING_KIND:
  1220.         tg[0].ti_Tag = GTST_String;
  1221.         break;
  1222.     case TEXT_KIND:
  1223.         tg[0].ti_Tag = GTTX_Text;
  1224.         break;
  1225.     } /* switch */
  1226.  
  1227.     GTB_SetGadgetAttrsA(gd, tg);
  1228.     } /* if */
  1229.  
  1230. } /* do_setgtbgadget */
  1231.  
  1232. /*DEFHELP #cmd gtb OPENGTBWINDOW project window - open a window of a GTB project */
  1233. DEFUSERCMD("OpenGTBWindow", 2, CF_VWM|CF_ICO|CF_COK, void, do_opengtbwindow, (void), )
  1234. {
  1235.     struct GTB_Project *prj;
  1236.     struct WinNode     *wn;
  1237.  
  1238.     if ((wn = _getgtbwindow())) {
  1239.     prj = (void *)wn->Node.Parent;
  1240.     GTB_Error (GTB_OpenWindow (wn, prj));
  1241.     }
  1242. } /* do_opengtbwindow */
  1243.  
  1244. /*DEFHELP #cmd gtb ACTIVATEGTBWINDOW project window - open a window of a GTB project */
  1245. DEFUSERCMD("ActivateGTBWindow", 2, CF_VWM|CF_ICO|CF_COK, void, do_activategtbwindow, (void), )
  1246. {
  1247.     struct WinNode     *wn;
  1248.  
  1249.     if ((wn = _getgtbwindow())) {
  1250.     if (wn->IntuiWindow)
  1251.         ActivateWindow (wn->IntuiWindow);
  1252.     else
  1253.         do_opengtbwindow();
  1254.     }
  1255. } /* do_opengtbwindow */
  1256.  
  1257. /*DEFHELP #cmd gtb CLOSEGTBWINDOW project window - close a window of a GTB project */
  1258. DEFUSERCMD("CloseGTBWindow", 2, CF_VWM|CF_ICO|CF_COK, void, do_closegtbwindow, (void), )
  1259. {
  1260.     struct GTB_Project *prj;
  1261.     struct WinNode     *wn;
  1262.  
  1263.     if ((wn = _getgtbwindow())) {
  1264.     prj = _getgtbproject();
  1265.     GTB_Error (GTB_CloseWindow (wn, prj));
  1266.     }
  1267. } /* closegtbwindow */
  1268.  
  1269. /*DEFHELP #cmd gtb LOADGTBPROJECT project filename - read a GTB .GUI File  */
  1270. DEFUSERCMD("LoadGTBProject", 2, CF_VWM|CF_ICO|CF_COK, void, do_loadgtbproject, (void), )
  1271. {
  1272.     GTB_Error (GTB_OpenProject (av[2], av[1]));
  1273. } /* loadgtbproject */
  1274.  
  1275. /*DEFHELP #cmd gtb DROPGTBPROJECT project - free the resources needed for a GTB Project */
  1276. DEFUSERCMD("DropGTBProject", 1, CF_VWM|CF_ICO|CF_COK, void, do_dropgtbproject, (void), )
  1277. {
  1278.     struct GTB_Project *prj;
  1279.     if ((prj = _getgtbproject()))
  1280.     GTB_Error (GTB_CloseProject (prj));
  1281. } /* dropgtbproject */
  1282.  
  1283.  
  1284.  
  1285. int GTB_Notify (struct GadNode *gadget, ULONG attr, APTR value, APTR *base) {
  1286. //printf ("Notification: %d %08lx\n", attr, value);
  1287.     struct TagItem tg[2] = { TAG_IGNORE, NULL, TAG_DONE };
  1288.     if (attr == HLA_Labels) {
  1289.     tg[0].ti_Tag  = GTLV_Labels;
  1290.     tg[0].ti_Data = (ULONG)value;
  1291.     GTB_SetGadgetAttrsA (gadget, tg);
  1292.     gadget->gdata = base;
  1293.     return 1;
  1294.     } /* if */
  1295.     return 0;
  1296. } /* GTB_Notify */
  1297.  
  1298. /*DEFHELP #cmd gtb CONNECTGTBGADGET prj win gad list - connect a gadtoolsgadget with a list */
  1299. DEFUSERCMD("ConnectGTBGadget", 4, CF_VWM|CF_ICO|CF_COK, void, do_connectgtbgadget, (void), )
  1300. {
  1301.     struct WinNode     *wn;
  1302.     struct GTB_Project *prj;
  1303.     struct GadNode     *gd;
  1304.     APTR        list;
  1305.  
  1306.     if (gd  = _getgtbgadget()) {
  1307.     wn  = (void *)gd->Node.Parent;
  1308.     prj = (void *)wn->Node.Parent;
  1309.  
  1310.     if (gd->GuiGadget->en_Kind != LISTVIEW_KIND) {
  1311.         error ("%s:\nConnect only works w/ Listviews!");
  1312.         return;
  1313.     } /* if */
  1314.  
  1315.     if (!(list = HL_LockNode(av[4]))) {
  1316.         error ("%s:\nCannot find List %s", av[0], av[4]);
  1317.         return;
  1318.     } /* if */
  1319.  
  1320.     if (gd->gdata)
  1321.         HL_Disconnect (gd->gdata, &gd->Node);
  1322.  
  1323.     HL_Connect (list, &gd->Node, HLA_Labels);
  1324.     } /* if */
  1325. } /* connectgtbgadget */
  1326.  
  1327.  
  1328. /*DEFLONG #long GTB,LOADGTBPROJECT,DROPGTBPROJECT,OPENGTBWINDOW,CLOSEGTBWINDOW,SETGTBGADGET
  1329.  
  1330. Interface To enable XDME to load and basically display (not everything is
  1331. currently handeled correctly) GadToolsBox Projects (namely ".GUI" Files)
  1332.  
  1333. the user has the possibility to draw his own asynch. requesters and load
  1334. and display them from within XDME; each time, a menu is selected
  1335. or a gadget is Selected (Select-UP), a XDME Command is called;
  1336.  
  1337. the command is currently build in the form
  1338. projectname"-"windowname"-"gadgetname" "value
  1339. for gadgets and
  1340. projectname"-"windowname"-"menuname" "value
  1341. for menus; value is the State of the toggle for a togglemenu,
  1342. the active label for a listview, and so on; for button-gadgets
  1343. and non-toggle menuitems, value is "".
  1344. (the format may be changed with the $gtbformat variable)
  1345.  
  1346. however I think about a more intuitive way of connecting
  1347. variables, gadgets and menues, so that macro-solution might
  1348. be removed in the near future ...
  1349.  
  1350. It is already possible to connect Listview Gadgets with Lists (see
  1351. the Lists section ... ahem where? =8-}) so that every change of a
  1352. List is immediately shown in the connected Listviews (sorry, but
  1353. the Cycle Gadgets are not yet supported nor any other structure
  1354. than Lists and LV-Gadgets, but this is a planned enhancement)
  1355.  
  1356.  
  1357.  
  1358. *WARNING* the GTB module is BETA and it is certainly not
  1359.   bulletproof - You should think twice about what You are
  1360.   doing ...
  1361.  
  1362. *BUG* (or not?) it is not defined whatever happens, if there is
  1363.   that Boopsi Pop-Image used inside a GTB Project, so better make
  1364.   sure it is not used ...
  1365.  
  1366. *BUG* (yea it is...) i have not (yet) added Fallback conditions,
  1367.   to make sure a window does not exceed Screensize... in that
  1368.   concern ... we do currently use the Screenfont also, if a
  1369.   non-topaz font was defined in the GTB Project (Any help how I can
  1370.   check, if the user wanted the GTB Project's font?)
  1371.  
  1372. *BUG* (probabely NOT subject of change) XDME ignores the settings
  1373.   for screens, it always uses the screen of the active TextWindow ...
  1374.  
  1375. *BUG* there is currently no support for Gadget Shortcuts in a
  1376.   GTB project (any suggestions?)
  1377.  
  1378. *BUG* there is currently no sufficient menu handling (e.g. setcheck
  1379.   is not possible)
  1380.  
  1381. */
  1382.  
  1383. /******************************************************************************
  1384. *****  END GTB.c
  1385. ******************************************************************************/
  1386.  
  1387.  
  1388. #ifdef TEST
  1389.  
  1390. #include <stdio.h>
  1391. #include <stdlib.h>
  1392.  
  1393.  
  1394.  
  1395. int main (int ac, char **av) {
  1396.     atexit (libclose);
  1397.     if (libopen() != 0) {
  1398. //fprintf (stderr, "noopenlib\n");
  1399.     return 20;
  1400.     }
  1401.  
  1402.     if (GTB_Initialize()) {
  1403.     atexit (GTB_Terminate);
  1404.  
  1405.     if (GTB_OpenProject("test.gui", "alpha") == GTB_OK) {
  1406.         if (GTB_OpenWindow (
  1407.         GetHead(
  1408.             &(((struct GTB_Project *)GetHead(
  1409.             GTB_Projects))->AppliWindows)),
  1410.         GetHead(GTB_Projects)) == GTB_OK)
  1411.         while (GTB_Handle())
  1412.             WaitPort (GTB_Port);
  1413.         return 0;
  1414.     } /* if */
  1415.     } /* if */
  1416.  
  1417.     return 10;
  1418. } /* main */
  1419.  
  1420.  
  1421. #endif /*  */
  1422.  
  1423.     DEFFLAG( 94-11-25, AmTerminating, 0 )
  1424.  
  1425. #ifdef SPC_VAR
  1426. // Information for Util/Var/Parser ...
  1427.  
  1428. spcvars += {
  1429.     strptr GtbFormat = {
  1430.     help = %[ format to convert Project, Window, Gadget|Menu and
  1431.           Value Information of a GTB_Signal %];
  1432.     reference = GTB_Format;
  1433.     };
  1434. };
  1435.  
  1436. sighandler GTB = {
  1437.     signal = "GTB_SigMask";
  1438.     code = %[ GTB_Handler(); %];
  1439. };
  1440.  
  1441. #endif
  1442.  
  1443.  
  1444. #if 0
  1445.  
  1446. // gtbgadget has no OM_NEW, since it cannot be created on User request
  1447.  
  1448. class gtbgadget = {
  1449.     superclass = rootclass;
  1450.     contents = {
  1451.     slot IntuiGadget = {
  1452.         type = "struct Gadget *";
  1453.     };
  1454.     slot LastCode = {
  1455.         type = "ULONG";
  1456.     };
  1457.     slot gdata = {
  1458.         type = "APTR";
  1459.     };
  1460.     slot GuiGadget = {
  1461.         type = "struct ExtNewGadget *";
  1462.     };
  1463.     };
  1464.  
  1465.     attribute HA_Label = {
  1466.     type = "STRPTR";
  1467.     S = {{
  1468.     }};
  1469.     G = {{
  1470.         *((struct opGet *)msg)->opg_Storage = inst->IntuiGadget->GadgetText->IText;
  1471.     }};
  1472.     };
  1473.  
  1474.     // only for Listview, Cycle
  1475.     attribute HA_LabelCarrier = {
  1476.     type = "HObject *";
  1477.     S = {{
  1478.     }};
  1479.     G = {{
  1480.     }};
  1481.     };
  1482.     attribute HA_GadValue = {
  1483.     S = {{
  1484.     }};
  1485.     G = {{
  1486.     }};
  1487.     };
  1488.     attribute HA_Disabled = {
  1489.     type = "BOOL";
  1490.     S = {{
  1491.     }};
  1492.     G = {{
  1493.     }};
  1494.     };
  1495. };
  1496.  
  1497. // gtbwindow has no OM_NEW, since it cannot be created on User request
  1498.  
  1499. class gtbwindow = {
  1500.  
  1501.     //struct Gadget       *IntuiGadgets;
  1502.     //struct Window       *IntuiWindow;
  1503.     //struct Menu       *IntuiMenus;
  1504.     //HObject           *AppliMenus;
  1505.     //struct ProjectWindow *GuiWindow;
  1506.  
  1507.     attribute HA_Visible = {
  1508.     type = "BOOL";
  1509.     S = {{
  1510.     }};
  1511.     G = {{
  1512.     }};
  1513.     };
  1514. };
  1515.  
  1516. // gtbmenu has no OM_NEW, since it cannot be created on User request
  1517.  
  1518. class gtbmenu = {
  1519.     superclass = subcarrierclass;
  1520.     contents = {
  1521.     slot IntuiMenu = {
  1522.         type = "struct Menu *";
  1523.     };
  1524.     slot GuiGadget = {
  1525.         type = "struct ExtNewMenu *";
  1526.     };
  1527.  
  1528.     };
  1529.  
  1530.     attribute HA_Label = {
  1531.     type = "STRPTR";
  1532.     S = {{
  1533.         inst->IntuiMenu->MenuName = strrep (inst->IntuiMenu->MenuName, (STRPTR)ti->ti_Data);
  1534.     }};
  1535.     G = {{
  1536.         *((struct opGet *)msg)->opg_Storage = inst->IntuiMenu->MenuName;
  1537.     }};
  1538.     };
  1539.  
  1540.     attribute HA_Disabled = {
  1541.     type = "BOOL";
  1542.     S = {{
  1543.         if (inst->IntuiMenu->Flags & ITEMENABLED)
  1544.         OffMenu (GetMenuPos(o));
  1545.         else
  1546.         OnMenu    (GetMenuPos(o));
  1547.     }};
  1548.     G = {{
  1549.         *((struct opGet *)msg)->opg_Storage = !(inst->IntuiMenu->Flags & ITEMENABLED);
  1550.     }};
  1551.     };
  1552. };
  1553. class gtbmenuitem = {
  1554.     superclass = subcarrierclass;
  1555.     contents = {
  1556.     slot IntuiMenu = {
  1557.         type = "struct MenuItem *";
  1558.     };
  1559.     slot GuiGadget = {
  1560.         type = "struct ExtNewMenu *";
  1561.     };
  1562.  
  1563.     };
  1564.  
  1565.     attribute HA_Label = {
  1566.     type = "STRPTR";
  1567.     S = {{
  1568.         if (IsTextItem(o))
  1569.         ((struct IntuiText *)inst->IntuiMenu->ItemFill)->IText = strrep (((struct IntuiText *)inst->IntuiMenu->ItemFill)->IText, (STRPTR)ti->ti_Data);
  1570.     }};
  1571.     G = {{
  1572.         if (IsTextItem(o))
  1573.         *((struct opGet *)msg)->opg_Storage = inst->IntuiMenu->MenuText->IText;
  1574.     }};
  1575.     };
  1576.  
  1577.     attribute HA_MenuCheck = {
  1578.     type = "BOOL";
  1579.     S = {{
  1580.     }};
  1581.     G = {{
  1582.         *((struct opGet *)msg)->opg_Storage = (inst->IntuiMenu->Flags & ITEMCHECKED);
  1583.     }};
  1584.     };
  1585.  
  1586.     attribute HA_Disabled = {
  1587.     type = "BOOL";
  1588.     S = {{
  1589.         if (inst->IntuiMenu->Flags & ITEMENABLED)
  1590.         OffMenu (GetMenuPos(o));
  1591.         else
  1592.         OnMenu    (GetMenuPos(o));
  1593.     }};
  1594.     G = {{
  1595.         *((struct opGet *)msg)->opg_Storage = !(inst->IntuiMenu->Flags & ITEMENABLED);
  1596.     }};
  1597.     };
  1598. };
  1599.  
  1600. #endif
  1601.